<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/assets/layui/css/layui.css">
</head>

<body>
    <h1 style="text-align: center;margin: 50px">欢迎来到李土鸡后台管理系统-分类添加</h1>
    <form class="layui-form" id="addSet">

        <div class="layui-form-item">
            <label class="layui-form-label">分类名称</label>
            <div class="layui-input-inline">
                <input type="text" name="cate_name" required lay-verify="required" placeholder="名字" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <input type="text" name="orderBy" required lay-verify="required" placeholder="值" autocomplete="off"
                    class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="addSetData">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</body>
<script src="/assets/layui/layui.js"></script>
<script>

    layui.use('form', function () {
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        var addForm = $('#addSet')
        
        // 监听提交
        form.on('submit(addSetData)', function (data) {
            // 1. 获取表单数据
            const formData = data.field;
            console.log(data.field);
            // $.post('/addList',data.field);
            $.ajax({
                type: 'post',
                url: '/addList',
                data: data.field,
                dataType: 'json'
            }).then(res => {
                const { code, message } = res
                if (code == 0) {
                    alert(message)
                    location.href = '/catelist'
                } else if (code == 1) {
                    alert(message)
                }
            })
            return false
        })
    })  
</script>

</html>